package com.freight.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.freight.base.dto.AreaDto;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.order.dto.*;
import com.freight.order.service.IOrderVoService;
import com.freight.order.service.OrderOrderService;
import com.freight.order.vo.*;
import com.freight.user.dto.CompanyDto;
import com.freight.user.dto.DriverDto;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "运单信息管理接口")
@RequestMapping("/freight/orderVo")
@Transactional
public class OrderVoController {

    @Autowired
    private IOrderVoService iOrderVoService;

    @RequestMapping(value = "/getOrderInfoByState", method = RequestMethod.POST)
    @ApiOperation(value = "平台端 ----- 获取所有运单信息")
    public Result<IPage<OrderVo>> getOrderInfoByState(PageVo page, SearchOrderDto searchOrderDto) {
        Page res = iOrderVoService.getOrderInfoByState(PageUtil.initMpPage(page), searchOrderDto);
        return new ResultUtil<IPage<OrderVo>>().setData(res);
    }

    @RequestMapping(value = "/getCompanyOrderInfoByState", method = RequestMethod.POST)
    @ApiOperation(value = "货主端 --- 获取货主的运单 分状态")
    public Result<IPage<OrderVo>> getCompanyOrderInfoByState(PageVo page, CompanySearchOrderDto companySearchOrderDto) {
        Page res = iOrderVoService.getCompanyOrderInfoByState(PageUtil.initMpPage(page), companySearchOrderDto);
        return new ResultUtil<IPage<OrderVo>>().setData(res);
    }

    @RequestMapping(value = "/getDriverOrderInfoByState", method = RequestMethod.POST)
    @ApiOperation(value = "司机端 ----- 获取司机的运单 分状态")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "orderStates",value = "订单状态",dataType = "String",paramType = "query",allowMultiple = true)
    })
    public Result<IPage<OrderVo>> getDriverOrderInfoByState(PageVo page, String[] orderStates) {
        Page res = iOrderVoService.getDriverOrderInfoByState(PageUtil.initMpPage(page),  orderStates);
        return new ResultUtil<IPage<OrderVo>>().setData(res);
    }

    @RequestMapping(value = "/getDriverOrderCompanyInfo", method = RequestMethod.POST)
    @ApiOperation(value = "司机看到的运单")
    public Result<IPage<DriverOrderCompanyVo>> getDriverOrderCompanyInfo(PageVo page) {
        Page res = iOrderVoService.getDriverOrderCompanyInfo(PageUtil.initMpPage(page));
        return new ResultUtil<IPage<DriverOrderCompanyVo>>().setData(res);
    }

    @RequestMapping(value = "/getOrderVoInfo", method = RequestMethod.GET)
    @ApiOperation(value = "获取运单详细信息")
    public Result<OrderVo> getOrderVoInfo(Long orderId) {
        OrderVo res = iOrderVoService.getOrderVoInfo(orderId);
        return new ResultUtil<OrderVo>().setData(res);
    }

}
